package org.geektimes.interceptor;

import org.geektimes.interceptor.cglib.InterceptorEnhancer;
import org.geektimes.interceptor.jdk.JdkProxyEnhancer;

/**
 * 组装 cglib & proxy.
 * <br> @author leo
 * <br> @date 2021/7/27
 * <br> @since 1.0.0
 */
public class AssembleProxy {

    private final Object target;

    private final Object [] interceptors;

    private final Class<?> interfaceClass;

    public AssembleProxy(Object target,Object [] interceptors) {
        this(target,interceptors,null);
    }

    public AssembleProxy(Object target, Object[] interceptors,Class<?> interfaceClass) {
        this.target = target;
        this.interceptors = interceptors;
        this.interfaceClass = interfaceClass;
    }

    public Object processed(){
       if (interfaceClass != null) {
           return new JdkProxyEnhancer(target,interceptors).invoke(interfaceClass);
       }
       return new InterceptorEnhancer().enhance(target,interceptors);
    }
}
